class Calculator {
    constructor(initValue = 0) {
        this.stack = [initValue];
    }
    add(value) {
        this.stack.push(value);
        return this;
    }
    sub(value) {
        this.stack.push(-value);
        return this;
    }
    mul(value) {
        const last = this.stack.pop();
        this.stack.push(last * value);
        return this;
    }
    div(value) {
        const last = this.stack.pop();
        this.stack.push(last / value);
        return this;
    }
    valueOf() {
        return this.stack.reduce((sum, num) => sum + num, 0);
    }
}
export default Calculator;